const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {

    mode: 'development',
    devtool: 'inline-source-map',

    devServer: {
        static: './dist',
        open: false, // 自动打开
        hot: true, // 热更新
        compress: false,  // gzip压缩，开发环境不开启，提升速度
    },

    cache: {
        type: 'filesystem',
        buildDependencies: {
            config: [__filename],
        },
        cacheDirectory: path.resolve(__dirname, 'temp_cache'),
        name: 'scf-cache',
        compression: 'gzip',
    },

    entry: './src/index.ts',
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist'),
        clean: true,
        publicPath: '/',
    },

    optimization: {
        runtimeChunk: 'single',
    },

    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.css$/i,
                use: ['style-loader', 'css-loader'],
            },
            {
                test: /\.(png|svg|jpg|jpeg|gif)$/i,
                type: 'asset/resource',
            },
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/i,
                type: 'asset/resource',
            },
            {
                test: /\.(glsl)$/,
                type: 'asset/source',  
            },
        ],
    },

    resolve: {
        extensions: ['.tsx', '.ts', '.js'],
    },

    plugins: [
        new HtmlWebpackPlugin({
            title: 'Development',
        }),
    ],
};